package com.arelikebrothers.demo.algorithm.basic.analysis;

import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;

/**
 * Created by lennon on 12/06/2017.
 */
public class IterableDemo implements Iterable<Integer> {
    private int[] data = {1, 2, 3, 1, 2, 3, 4};

    @Override
    public Iterator<Integer> iterator() {
        return new Iterator<Integer>() {
            private int index = 0;

            @Override
            public boolean hasNext() {
                return index < data.length;
            }

            @Override
            public Integer next() {
                Integer value = data[index];
                index++;
                return value;
            }
        };
    }

    @Override
    public void forEach(Consumer<? super Integer> action) {

    }

    @Override
    public Spliterator<Integer> spliterator() {
        return null;
    }

    public static void main(String[] args) {
        IterableDemo demo = new IterableDemo();
        for (int a : demo) {
            System.out.println(a);
        }
    }
}
